<?php
namespace app\middleware;

use app\model\Sender as ModelSender;
use think\Request;

class Sender
{
    public function handle(Request $request, \Closure $next)
    {
        $event = $request->post("event");
        $sender = $event['sender'];
        $model = ModelSender::where([
            'sender_id' => $sender['senderId'],
            'sender_type' => $sender['senderType']
        ])->find();
        if(!$model) {
            $model = ModelSender::create([
                'sender_id' => $sender['senderId'],
                'sender_type' => $sender['senderType'],
            ]);
        }
        if($model->auth_status != 1){
            return response('未授权', 403);
        }
        return $next($request);
    }
}